<?php
/**
 * 用户提现表
 */
namespace app\common\model;

use think\Model;

class MemberWithdrawal  extends Model
{
    protected $name = 'member_withdrawal';

    /**
     * 添加用户提现记录
     * @param $mid  用户ID
     * @param $address   用户收款地址
     * @param $money    提现金额
     * @param $currency 币种
     * @param int $charge   手续费
     * @param int $chain_id 链地址
     * @return int|string
     */
    public static function add_withdrawal($mid,$address,$money,$currency,$charge = 0,$chain_id = 1){
        $data = [
            'mid'   =>  $mid,
            'address'   =>  $address,
            'chain_id'  =>  $chain_id,
            'currency'  =>  $currency,
            'money' =>  $money,
            'charge_money'  =>  $charge,
            'add_time'  =>  date('Y-m-d H:i:s',time()),
            'update_time'  =>  date('Y-m-d H:i:s',time())
        ];
        $id = self::insertGetId($data);
        return $id;
    }

    /**
     * 查询提现记录列表
     * @param array $where  查询条件
     * @param int $page 页码
     * @param int $limit    每页数量
     * @param string $order 排序
     * @return array
     * @throws \think\db\exception\DbException
     */
    public static function getList($where = [],$page = 1,$limit = 20,$order = 'id desc'){
        $data = self::where($where)->order($order)->paginate(['list_rows'=>$limit,'page'=>$page])->toArray();
        return $data;
    }

}